package cn.ghx.xboot.order.appointment;

import cn.ghx.xboot.common.Result;
import cn.ghx.xboot.order.dto.OrderStatusDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order/appointment")
public class OrderAppointmentController {

    public static final String POST = "";
    public static final String GET_LIST = "/list";
    public static final String DELETE = "/{id}";
    public static final String GET_BY_ID = "/{id}";
    public static final String PUT_STATUS = "/status";

    private final OrderAppointmentService service;

    public OrderAppointmentController(OrderAppointmentService service) {
        this.service = service;
    }

    @GetMapping(GET_BY_ID)
    public Result<OrderAppointment> getById(@PathVariable String id) {
        return Result.success(service.findById(id));
    }
    @PutMapping(PUT_STATUS)
    public Result<Boolean> putStatus(@RequestBody OrderStatusDto dto) {
        return Result.success(service.changeStatus(dto));
    }


    @DeleteMapping(DELETE)
    public Result<Boolean> delete(@PathVariable String id) {
        return Result.success(service.deleteById(id));
    }

    @PostMapping(POST)
    public Result<Boolean> save(@RequestBody OrderAppointment item) {
        return Result.success(service.saveItem(item));
    }

    @GetMapping(GET_LIST)
    public Result<Page<OrderAppointment>> getList(
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) String openid,
            @RequestParam(required = false) String phone,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false, defaultValue = "1") Integer page,
            @RequestParam(required = false, defaultValue = "10") Integer size) {
        return Result.success(service.query(keyword,
                openid,
                phone,
                status,
                page, size));
    }
}
